#!/usr/bin/python
from google.appengine.ext import db


class Alerts(db.Model):
    date = db.DateTimeProperty(auto_now_add=True)
    type = db.StringProperty()
    message = db.TextProperty()

def signal(type, message=''):
    Alerts(
        type = type,
        message = message
    ).put()

def getHtmlParams(args):
    items = []
    for item in Alerts.all().order('-date').fetch(100):
        items.append({
            'date': item.date.strftime('%H:%M:%S'),
            'type': item.type,
            'message': item.message
        })
    notify = '!wsss';
    output = {
       'items': items,
       'notify': notify
    }
    return output

def delete(action):
    all = Alerts.all()
    if action == 'start':
        to_delete = all.filter('type =', action)
    elif action == 'all':
        to_delete = all
    count = to_delete.count()
    db.delete(to_delete.fetch(1000))
    return count

    
    